```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>深入解析TreeMap和TreeSet | 技术小馆</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            line-height: 1.8;
            color: #333;
            background-color: #f9fafb;
        }
        .hero {
            background: linear-gradient(135deg, #6e8efb, #a777e3);
        }
        .code-block {
            background-color: #2d3748;
            border-radius: 0.5rem;
            color: #e2e8f0;
        }
        .code-keyword {
            color: #f6ad55;
        }
        .code-type {
            color: #68d391;
        }
        .code-string {
            color: #f687b3;
        }
        .code-comment {
            color: #a0aec0;
        }
        .card {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .feature-icon {
            width: 48px;
            height: 48px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 12px;
            font-size: 24px;
        }
        .drop-cap:first-letter {
            float: left;
            font-size: 4rem;
            line-height: 0.8;
            margin: 0.2em 0.3em 0 0;
            color: #6e8efb;
            font-weight: bold;
        }
        .nav-item {
            position: relative;
        }
        .nav-item::after {
            content: '';
            position: absolute;
            bottom: -5px;
            left: 0;
            width: 0;
            height: 2px;
            background-color: #6e8efb;
            transition: width 0.3s ease;
        }
        .nav-item:hover::after {
            width: 100%;
        }
        .mermaid {
            background-color: white;
            border-radius: 0.5rem;
            padding: 1.5rem;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }
    </style>
</head>
<body class="antialiased">
    <!-- 导航栏 -->
    <nav class="bg-white shadow-sm sticky top-0 z-50">
        <div class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="flex justify-between h-16">
                <div class="flex items-center">
                    <span class="text-xl font-bold text-gray-800">
                        <i class="fas fa-code mr-2 text-blue-500"></i>技术小馆
                    </span>
                </div>
                <div class="flex items-center space-x-8">
                    <a href="#" class="nav-item text-gray-700 hover:text-blue-600 transition-colors">首页</a>
                    <a href="#" class="nav-item text-gray-700 hover:text-blue-600 transition-colors">Java专题</a>
                    <a href="#" class="nav-item text-gray-700 hover:text-blue-600 transition-colors">数据结构</a>
                    <a href="#" class="nav-item text-gray-700 hover:text-blue-600 transition-colors">关于</a>
                </div>
            </div>
        </div>
    </nav>

    <!-- Hero 区域 -->
    <header class="hero text-white py-20">
        <div class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <h1 class="text-4xl md:text-5xl font-bold leading-tight mb-4">深入解析<span class="bg-white text-blue-600 px-2 rounded-md">TreeMap</span>和<span class="bg-white text-purple-600 px-2 rounded-md">TreeSet</span></h1>
                    <p class="text-xl mb-8 opacity-90">探索Java集合框架中基于红黑树的有序数据结构实现原理</p>
                    <div class="flex space-x-4">
                        <a href="#intro" class="bg-white text-blue-600 px-6 py-3 rounded-lg font-medium hover:bg-gray-100 transition-colors">
                            <i class="fas fa-book-open mr-2"></i>开始阅读
                        </a>
                        <a href="#summary" class="border-2 border-white text-white px-6 py-3 rounded-lg font-medium hover:bg-white hover:text-blue-600 transition-colors">
                            <i class="fas fa-list-check mr-2"></i>核心要点
                        </a>
                    </div>
                </div>
                <div class="md:w-1/2">
                    <div class="mermaid">
                        graph TD
                            A[红黑树] --> B[TreeMap]
                            A --> C[TreeSet]
                            B --> D[键值对存储]
                            B --> E[NavigableMap接口]
                            C --> F[元素唯一]
                            C --> G[NavigableSet接口]
                            A --> H[自平衡二叉查找树]
                            H --> I[查找O(log n)]
                            H --> J[插入O(log n)]
                            H --> K[删除O(log n)]
                    </div>
                </div>
            </div>
        </div>
    </header>

    <!-- 主要内容 -->
    <main class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
        <!-- 引言 -->
        <section id="intro" class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden p-8 card">
                <div class="drop-cap">
                    <p class="text-gray-700 text-lg leading-relaxed mb-6">
                        TreeMap 和 TreeSet 是 Java 集合框架中的两种重要数据结构，它们都基于红黑树（Red-Black Tree）实现，提供了有序的元素存储和操作方式。TreeMap 用于存储键值对（key-value），而 TreeSet 用于存储不重复的元素。它们的底层实现原理非常相似，但由于存储结构和用途的不同，具体实现也有所区别。
                    </p>
                    <div class="flex items-center text-blue-600">
                        <i class="fas fa-lightbulb text-xl mr-2"></i>
                        <span class="font-medium">红黑树是这两种数据结构的核心，理解红黑树是掌握TreeMap和TreeSet的关键</span>
                    </div>
                </div>
            </div>
        </section>

        <!-- 红黑树部分 -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold text-gray-800 mb-8 flex items-center">
                <span class="bg-blue-100 text-blue-600 p-2 rounded-lg mr-4">
                    <i class="fas fa-tree"></i>
                </span>
                <span>1. 红黑树数据结构的基础</span>
            </h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-md overflow-hidden p-8 card">
                    <h3 class="text-2xl font-semibold text-gray-800 mb-4">红黑树概述</h3>
                    <p class="text-gray-700 mb-4">
                        红黑树是一种自平衡的二叉查找树，它具有以下特点：
                    </p>
                    <ul class="space-y-3 text-gray-700 mb-6">
                        <li class="flex items-start">
                            <span class="bg-blue-100 text-blue-600 rounded-full w-6 h-6 flex items-center justify-center mr-3 flex-shrink-0">1</span>
                            <span>每个节点要么是红色，要么是黑色。</span>
                        </li>
                        <li class="flex items-start">
                            <span class="bg-blue-100 text-blue-600 rounded-full w-6 h-6 flex items-center justify-center mr-3 flex-shrink-0">2</span>
                            <span>根节点是黑色。</span>
                        </li>
                        <li class="flex items-start">
                            <span class="bg-blue-100 text-blue-600 rounded-full w-6 h-6 flex items-center justify-center mr-3 flex-shrink-0">3</span>
                            <span>每个叶子节点（<code class="bg-gray-100 px-1 rounded">NIL</code> 节点）是黑色。</span>
                        </li>
                        <li class="flex items-start">
                            <span class="bg-blue-100 text-blue-600 rounded-full w-6 h-6 flex items-center justify-center mr-3 flex-shrink-0">4</span>
                            <span>红色节点的子节点必须是黑色。</span>
                        </li>
                        <li class="flex items-start">
                            <span class="bg-blue-100 text-blue-600 rounded-full w-6 h-6 flex items-center justify-center mr-3 flex-shrink-0">5</span>
                            <span>从根节点到每个叶子节点的路径上，黑色节点的数量必须相同。</span>
                        </li>
                    </ul>
                    <p class="text-gray-700">
                        红黑树的高度是平衡的，因此它的查找、插入和删除操作的时间复杂度为 <code class="bg-gray-100 px-1 rounded">O(log n)</code>。
                    </p>
                </div>
                
                <div class="bg-white rounded-xl shadow-md overflow-hidden p-8 card">
                    <h3 class="text-2xl font-semibold text-gray-800 mb-4">红黑树可视化</h3>
                    <div class="mermaid">
                        graph TD
                            R((5:黑)) --> A((3:红))
                            R --> B((8:红))
                            A --> C((2:黑))
                            A --> D((4:黑))
                            B --> E((7:黑))
                            B --> F((9:黑))
                            style R fill:#2d3748,color:#fff
                            style A fill:#f56565,color:#fff
                            style B fill:#f56565,color:#fff
                            style C fill:#2d3748,color:#fff
                            style D fill:#2d3748,color:#fff
                            style E fill:#2d3748,color:#fff
                            style F fill:#2d3748,color:#fff
                    </div>
                    <p class="text-gray-700 mt-4 text-sm">
                        图示：一个简单的红黑树示例，展示了颜色和平衡特性。红色节点不能连续，每条路径的黑色节点数量相同。
                    </p>
                </div>
            </div>
        </section>

        <!-- TreeMap部分 -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold text-gray-800 mb-8 flex items-center">
                <span class="bg-purple-100 text-purple-600 p-2 rounded-lg mr-4">
                    <i class="fas fa-map-marked-alt"></i>
                </span>
                <span>2. TreeMap 的实现原理</span>
            </h2>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8 card">
                <div class="p-8">
                    <h3 class="text-2xl font-semibold text-gray-800 mb-4">TreeMap 基本结构</h3>
                    <p class="text-gray-700 mb-6">
                        <code class="bg-gray-100 px-1 rounded">TreeMap</code> 实现了 <code class="bg-gray-100 px-1 rounded">NavigableMap</code> 接口，而 <code class="bg-gray-100 px-1 rounded">NavigableMap</code> 继承自 <code class="bg-gray-100 px-1 rounded">SortedMap</code>。<code class="bg-gray-100 px-1 rounded">TreeMap</code> 的核心数据结构是一个红黑树。每个树节点包含一个键值对（<code class="bg-gray-100 px-1 rounded">key</code> 和 <code class="bg-gray-100 px-1 rounded">value</code>），并根据 <code class="bg-gray-100 px-1 rounded">key</code> 进行排序。
                    </p>
                    
                    <div class="code-block p-6 rounded-lg mb-6">
                        <pre><code><span class="code-keyword">public class</span> <span class="code-type">TreeMap</span>&lt;<span class="code-type">K</span>,<span class="code-type">V</span>&gt; <span class="code-keyword">extends</span> <span class="code-type">AbstractMap</span>&lt;<span class="code-type">K</span>,<span class="code-type">V</span>&gt; 
    <span class="code-keyword">implements</span> <span class="code-type">NavigableMap</span>&lt;<span class="code-type">K</span>,<span class="code-type">V</span>&gt;, <span class="code-type">Cloneable</span>, <span class="code-type">java.io.Serializable</span> {

    <span class="code-keyword">transient</span> <span class="code-type">Entry</span>&lt;<span class="code-type">K</span>,<span class="code-type">V</span>&gt; root; <span class="code-comment">// 红黑树的根节点</span>
    <span class="code-keyword">transient int</span> size = <span class="code-keyword">0</span>; <span class="code-comment">// TreeMap 中的元素数量</span>
    <span class="code-keyword">private final</span> <span class="code-type">Comparator</span>&lt;? <span class="code-keyword">super</span> <span class="code-type">K</span>&gt; comparator; <span class="code-comment">// 用于排序的比较器</span>
    <span class="code-keyword">private transient int</span> modCount = <span class="code-keyword">0</span>; <span class="code-comment">// 记录结构修改次数</span>
}</code></pre>
                    </div>
                </div>
                
                <div class="border-t border-gray-200 p-8">
                    <h3 class="text-2xl font-semibold text-gray-800 mb-4">TreeMap 插入过程</h3>
                    <p class="text-gray-700 mb-6">
                        <code class="bg-gray-100 px-1 rounded">TreeMap</code> 中的插入操作通过红黑树实现，在插入新节点时会保持红黑树的平衡。插入的过程包括查找合适的位置并插入节点，然后进行必要的旋转和颜色调整。
                    </p>
                    
                    <div class="code-block p-6 rounded-lg mb-6">
                        <pre><code><span class="code-keyword">public</span> <span class="code-type">V</span> <span class="code-keyword">put</span>(<span class="code-type">K</span> key, <span class="code-type">V</span> value) {
    <span class="code-type">Entry</span>&lt;<span class="code-type">K</span>,<span class="code-type">V</span>&gt; t = root;
    <span class="code-keyword">if</span> (t == <span class="code-keyword">null</span>) {
        compare(key, key);  <span class="code-comment">// 防止 null 键</span>
        root = <span class="code-keyword">new</span> <span class="code-type">Entry</span>&lt;&gt;(key, value, <span class="code-keyword">null</span>);
        size = <span class="code-keyword">1</span>;
        modCount++;
        <span class="code-keyword">return</span> <span class="code-keyword">null</span>;
    }
    <span class="code-keyword">int</span> cmp;
    <span class="code-type">Entry</span>&lt;<span class="code-type">K</span>,<span class="code-type">V</span>&gt; parent;
    <span class="code-comment">// 查找合适的位置</span>
    <span class="code-keyword">do</span> {
        parent = t;
        cmp = compare(key, t.key);
        <span class="code-keyword">if</span> (cmp &lt; <span class="code-keyword">0</span>)
            t = t.left;
        <span class="code-keyword">else if</span> (cmp &gt; <span class="code-keyword">0</span>)
            t = t.right;
        <span class="code-keyword">else</span>
            <span class="code-keyword">return</span> t.setValue(value); <span class="code-comment">// 如果键已经存在，更新 value</span>
    } <span class="code-keyword">while</span> (t != <span class="code-keyword">null</span>);
    
    <span class="code-comment">// 在合适的位置插入节点</span>
    <span class="code-type">Entry</span>&lt;<span class="code-type">K</span>,<span class="code-type">V</span>&gt; e = <span class="code-keyword">new</span> <span class="code-type">Entry</span>&lt;&gt;(key, value, parent);
    <span class="code-keyword">if</span> (cmp &lt; <span class="code-keyword">0</span>)
        parent.left = e;
    <span class="code-keyword">else</span>
        parent.right = e;
    
    <span class="code-comment">// 旋转和颜色调整</span>
    fixAfterInsertion(e);
    size++;
    modCount++;
    <span class="code-keyword">return</span> <span class="code-keyword">null</span>;
}</code></pre>
                    </div>
                    
                    <div class="grid md:grid-cols-3 gap-4 mt-6">
                        <div class="bg-blue-50 p-4 rounded-lg">
                            <div class="feature-icon bg-blue-100 text-blue-600 mb-3">
                                <i class="fas fa-search"></i>
                            </div>
                            <h4 class="font-semibold text-gray-800 mb-2">查找位置</h4>
                            <p class="text-gray-700 text-sm">根据 <code class="bg-blue-100 px-1 rounded">key</code> 比较找到合适的位置</p>
                        </div>
                        <div class="bg-purple-50 p-4 rounded-lg">
                            <div class="feature-icon bg-purple-100 text-purple-600 mb-3">
                                <i class="fas fa-plus-circle"></i>
                            </div>
                            <h4 class="font-semibold text-gray-800 mb-2">插入节点</h4>
                            <p class="text-gray-700 text-sm">找到位置后创建新的节点并插入</p>
                        </div>
                        <div class="bg-green-50 p-4 rounded-lg">
                            <div class="feature-icon bg-green-100 text-green-600 mb-3">
                                <i class="fas fa-balance-scale"></i>
                            </div>
                            <h4 class="font-semibold text-gray-800 mb-2">平衡调整</span></h4>
                            <p class="text-gray-700 text-sm">调用 <code class="bg-green-100 px-1 rounded">fixAfterInsertion</code> 保持平衡</p>
                        </div>
                    </div>
                </div>
                
                <div class="border-t border-gray-200 p-8 bg-gray-50 rounded-b-xl">
                    <h3 class="text-2xl font-semibold text-gray-800 mb-4">fixAfterInsertion：插入后平衡树</h3>
                    <p class="text-gray-700 mb-6">
                        插入节点后，可能需要通过旋转和重新着色来维持红黑树的性质。这个操作确保了树的高度保持平衡，从而保证操作效率。
                    </p>
                    
                    <div class="code-block p-6 rounded-lg">
                        <pre><code><span class="code-keyword">private void</span> fixAfterInsertion(<span class="code-type">Entry</span>&lt;<span class="code-type">K</span>,<span class="code-type">V</span>&gt; x) {
    x.color = RED;
    <span class="code-keyword">while</span> (x != <span class="code-keyword">null</span> && x != root && x.parent.color == RED) {
        <span class="code-keyword">if</span> (parentOf(x) == leftOf(parentOf(parentOf(x)))) {
            <span class="code-type">Entry</span>&lt;<span class="code-type">K</span>,<span class="code-type">V</span>&gt; y = rightOf(parentOf(parentOf(x)));
            <span class="code-keyword">if</span> (colorOf(y) == RED) {
                setColor(parentOf(x), BLACK);
                setColor(y, BLACK);
                setColor(parentOf(parentOf(x)), RED);
                x = parentOf(parentOf(x));
            } <span class="code-keyword">else</span> {
                <span class="code-keyword">if</span> (x == rightOf(parentOf(x))) {
                    x = parentOf(x);
                    leftRotate(x);
                }
                setColor(parentOf(x), BLACK);
                setColor(parentOf(parentOf(x)), RED);
                rightRotate(parentOf(parentOf(x)));
            }
        } <span class="code-keyword">else</span> {
            <span class="code-type">Entry</span>&lt;<span class="code-type">K</span>,<span class="code-type">V</span>&gt; y = leftOf(parentOf(parentOf(x)));
            <span class="code-keyword">if</span> (colorOf(y) == RED) {
                setColor(parentOf(x), BLACK);
                setColor(y, BLACK);
                setColor(parentOf(parentOf(x)), RED);
                x = parentOf(parentOf(x));
            } <span class="code-keyword">else</span> {
                <span class="code-keyword">if</span> (x == leftOf(parentOf(x))) {
                    x = parentOf(x);
                    rightRotate(x);
                }
                setColor(parentOf(x), BLACK);
                setColor(parentOf(parentOf(x)), RED);
                leftRotate(parentOf(parentOf(x)));
            }
        }
    }
    root.color = BLACK;
}</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <!-- TreeSet部分 -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold text-gray-800 mb-8 flex items-center">
                <span class="bg-green-100 text-green-600 p-2 rounded-lg mr-4">
                    <i class="fas fa-layer-group"></i>
                </span>
                <span>3. TreeSet 的实现原理</span>
            </h2>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden card">
                <div class="p-8">
                    <h3 class="text-2xl font-semibold text-gray-800 mb-4">TreeSet 的实现</h3>
                    <p class="text-gray-700 mb-6">
                        <code class="bg-gray-100 px-1 rounded">TreeSet</code> 和 <code class="bg-gray-100 px-1 rounded">TreeMap</code> 很相似，不同之处在于 <code class="bg-gray-100 px-1 rounded">TreeSet</code> 不存储值，只存储键。内部结构使用 <code class="bg-gray-100 px-1 rounded">TreeMap</code> 来实现，而 <code class="bg-gray-100 px-1 rounded">TreeMap</code> 中的 <code class="bg-gray-100 px-1 rounded">key</code> 就是 <code class="bg-gray-100 px-1 rounded">TreeSet</code> 中的元素。
                    </p>
                    
                    <div class="code-block p-6 rounded-lg mb-6">
                        <pre><code><span class="code-keyword">public class</span> <span class="code-type">TreeSet</span>&lt;<span class="code-type">E</span>&gt; <span class="code-keyword">extends</span> <span class="code-type">AbstractSet</span>&lt;<span class="code-type">E</span>&gt; 
    <span class="code-keyword">implements</span> <span class="code-type">NavigableSet</span>&lt;<span class="code-type">E</span>&gt;, <span class="code-type">Cloneable</span>, <span class="code-type">java.io.Serializable</span> {

    <span class="code-keyword">private transient</span> <span class="code-type">TreeMap</span>&lt;<span class="code-type">E</span>,<span class="code-type">Object</span>&gt; m; <span class="code-comment">// 使用 TreeMap 来存储元素</span>

    <span class="code-keyword">private static final</span> <span class="code-type">Object</span> PRESENT = <span class="code-keyword">new</span> <span class="code-type">Object</span>(); <span class="code-comment">// 常量，表示存在的元素</span>

    <span class="code-keyword">public</span> <span class="code-type">TreeSet</span>() {
        m = <span class="code-keyword">new</span> <span class="code-type">TreeMap</span>&lt;&gt;();
    }

    <span class="code-keyword">public boolean</span> add(<span class="code-type">E</span> e) {
        <span class="code-keyword">return</span> m.put(e, PRESENT) == <span class="code-keyword">null</span>;  <span class="code-comment">// 利用 TreeMap 的 put 方法来添加元素</span>
    }

    <span class="code-keyword">public boolean</span> contains(<span class="code-type">Object</span> o) {
        <span class="code-keyword">return</span> m.containsKey(o);  <span class="code-comment">// 判断元素是否存在</span>
    }

    <span class="code-keyword">public boolean</span> remove(<span class="code-type">Object</span> o) {
        <span class="code-keyword">return</span> m.remove(o) == PRESENT;  <span class="code-comment">// 移除元素</span>
    }
}</code></pre>
                    </div>
                    
                    <div class="grid md:grid-cols-2 gap-6 mt-6">
                        <div class="bg-white border border-gray-200 rounded-lg p-6">
                            <h4 class="font-semibold text-gray-800 mb-3">TreeSet 特性</h4>
                            <ul class="space-y-2 text-gray-700">
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                    <span>底层通过 <code class="bg-gray-100 px-1 rounded">TreeMap</code> 实现</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                    <span>只存储键，不存储值</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                    <span>元素自动排序</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                    <span>保证元素唯一性</span>
                                </li>
                            </ul>
                        </div>
                        <div class="bg-white border border-gray-200 rounded-lg p-6">
                            <h4 class="font-semibold text-gray-800 mb-3">性能特点</h4>
                            <ul class="space-y-2 text-gray-700">
                                <li class="flex items-start">
                                    <i class="fas fa-bolt text-yellow-500 mt-1 mr-2"></i>
                                    <span>查找：<code class="bg-gray-100 px-1 rounded">O(log n)</code></span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-bolt text-yellow-500 mt-1 mr-2"></i>
                                    <span>插入：<code class="bg-gray-100 px-1 rounded">O(log n)</code></span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-bolt text-yellow-500 mt-1 mr-2"></i>
                                    <span>删除：<code class="bg-gray-100 px-1 rounded">O(log n)</code></span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-bolt text-yellow-500 mt-1 mr-2"></i>
                                    <span>基于红黑树实现</span>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- 查找与删除操作 -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold text-gray-800 mb-8 flex items-center">
                <span class="bg-yellow-100 text-yellow-600 p-2 rounded-lg mr-4">
                    <i class="fas fa-search-minus"></i>
                </span>
                <span>4. 查找与删除操作</span>
            </h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-md overflow-hidden p-8 card">
                    <h3 class="text-2xl font-semibold text-gray-800 mb-4">查找操作</h3>
                    <p class="text-gray-700 mb-6">
                        <code class="bg-gray-100 px-1 rounded">TreeMap</code> 和 <code class="bg-gray-100 px-1 rounded">TreeSet</code> 的查找操作都基于红黑树的查找方式。通过 <code class="bg-gray-100 px-1 rounded">compare()</code> 方法来比较键值，查找时间复杂度是 <code class="bg-gray-100 px-1 rounded">O(log n)</code>。
                    </p>
                    
                    <div class="code-block p-6 rounded-lg">
                        <pre><code><span class="code-keyword">public</span> <span class="code-type">V</span> get(<span class="code-type">Object</span> key) {
    <span class="code-type">Entry</span>&lt;<span class="code-type">K</span>,<span class="code-type">V</span>&gt; p = getEntry(key);
    <span class="code-keyword">return</span> (p == <span class="code-keyword">null</span>) ? <span class="code-keyword">null</span> : p.value;
}</code></pre>
                    </div>
                </div>
                
                <div class="bg-white rounded-xl shadow-md overflow-hidden p-8 card">
                    <h3 class="text-2xl font-semibold text-gray-800 mb-4">删除操作</h3>
                    <p class="text-gray-700 mb-6">
                        删除操作需要先找到要删除的节点，然后通过旋转和颜色调整来保持红黑树的平衡。删除操作的时间复杂度也是 <code class="bg-gray-100 px-1 rounded">O(log n)</code>。
                    </p>
                    
                    <div class="code-block p-6 rounded-lg">
                        <pre><code><span class="code-keyword">public</span> <span class="code-type">V</span> remove(<span class="code-type">Object</span> key) {
    <span class="code-type">Entry</span>&lt;<span class="code-type">K</span>,<span class="code-type">V</span>&gt; p = getEntry(key);
    <span class="code-keyword">if</span> (p == <span class="code-keyword">null</span>)
        <span class="code-keyword">return</span> <span class="code-keyword">null</span>;

    deleteEntry(p);
    <span class="code-keyword">return</span> p.value;
}</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <!-- 总结 -->
        <section id="summary" class="mb-16">
            <div class="bg-blue-50 rounded-xl p-8">
                <h2 class="text-3xl font-bold text-gray-800 mb-6">5. 总结</h2>
                <div class="grid md:grid-cols-2 gap-6">
                    <div>
                        <h3 class="text-xl font-semibold text-gray-800 mb-4 flex items-center">
                            <i class="fas fa-check-circle text-blue-600 mr-2"></i>
                            <span>核心要点</span>
                        </h3>
                        <ul class="space-y-3 text-gray-700">
                            <li class="flex items-start">
                                <span class="bg-blue-100 text-blue-600 rounded-full w-5 h-5 flex items-center justify-center mr-3 flex-shrink-0 text-xs">✓</span>
                                <span><code class="bg-blue-100 px-1 rounded">TreeMap</code> 和 <code class="bg-blue-100 px-1 rounded">TreeSet</code> 都基于红黑树实现</span>
                            </li>
                            <li class="flex items-start">
                                <span class="bg-blue-100 text-blue-600 rounded-full w-5 h-5 flex items-center justify-center mr-3 flex-shrink-0 text-xs">✓</span>
                                <span><code class="bg-blue-100 px-1 rounded">TreeMap</code> 存储键值对，<code class="bg-blue-100 px-1 rounded">TreeSet</code> 只存储键</span>
                            </li>
                            <li class="flex items-start">
                                <span class="bg-blue-100 text-blue-600 rounded-full w-5 h-5 flex items-center justify-center mr-3 flex-shrink-0 text-xs">✓</span>
                                <span>插入和删除操作会触发红黑树的旋转和颜色调整</span>
                            </li>
                            <li class="flex items-start">
                                <span class="bg-blue-100 text-blue-600 rounded-full w-5 h-5 flex items-center justify-center mr-3 flex-shrink-0 text-xs">✓</span>
                                <span><code class="bg-blue-100 px-1 rounded">TreeSet</code> 是 <code class="bg-blue-100 px-1 rounded">TreeMap</code> 的一个封装</span>
                            </li>
                        </ul>
                    </div>
                    <div>
                        <h3 class="text-xl font-semibold text-gray-800 mb-4 flex items-center">
                            <i class="fas fa-clock text-blue-600 mr-2"></i>
                            <span>时间复杂度</span>
                        </h3>
                        <div class="bg-white rounded-lg p-4 shadow-sm">
                            <div class="flex justify-between py-2 border-b border-gray-100">
                                <span class="text-gray-700">操作</span>
                                <span class="text-gray-700">复杂度</span>
                            </div>
                            <div class="flex justify-between py-2 border-b border-gray-100">
                                <span class="text-gray-700">查找</span>
                                <span class="text-blue-600 font-medium">O(log n)</span>
                            </div>
                            <div class="flex justify-between py-2 border-b border-gray-100">
                                <span class="text-gray-700">插入</span>
                                <span class="text-blue-600 font-medium">O(log n)</span>
                            </div>
                            <div class="flex justify-between py-2">
                                <span class="text-gray-700">删除</span>
                                <span class="text-blue-600 font-medium">O(log n)</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- 扩展阅读 -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold text-gray-800 mb-8 flex items-center">
                <span class="bg-indigo-100 text-indigo-600 p-2 rounded-lg mr-4">
                    <i class="fas fa-book"></i>
                </span>
                <span>扩展阅读</span>
            </h2>
            
            <div class="grid md:grid-cols-3 gap-6">
                <a href="#" class="bg-white rounded-xl shadow-md overflow-hidden card group">
                    <div class="p-6">
                        <div class="bg-indigo-100 text-indigo-600 w-12 h-12 rounded-lg flex items-center justify-center mb-4">
                            <i class="fas fa-project-diagram"></i>
                        </div>
                        <h3 class="text-xl font-semibold text-gray-800 mb-2 group-hover:text-indigo-600 transition-colors">红黑树详细实现分析</h3>
                        <p class="text-gray-600 text-sm">深入探讨红黑树的旋转操作和平衡机制</p>
                    </div>
                </a>
                
                <a href="#" class="bg-white rounded-xl shadow-md overflow-hidden card group">
                    <div class="p-6">
                        <div class="bg-purple-100 text-purple-600 w-12 h-12 rounded-lg flex items-center justify-center mb-4">
                            <i class="fas fa-chart-bar"></i>
                        </div>
                        <h3 class="text-xl font-semibold text-gray-800 mb-2 group-hover:text-purple-600 transition-colors">Java集合框架对比</h3>
                        <p class="text-gray-600 text-sm">HashMap vs TreeMap vs LinkedHashMap 性能比较</p>
                    </div>
                </a>
                
                <a href="#" class="bg-white rounded-xl shadow-md overflow-hidden card group">
                    <div class="p-6">
                        <div class="bg-blue-100 text-blue-600 w-12 h-12 rounded-lg flex items-center justify-center mb-4">
                            <i class="fas fa-code-branch"></i>
                        </div>
                        <h3 class="text-xl font-semibold text-gray-800 mb-2 group-hover:text-blue-600 transition-colors">Java 8中的集合优化</h3>
                        <p class="text-gray-600 text-sm">探索Java 8对集合框架的改进和新特性</p>
                    </div>
                </a>
            </div>
        </section>
    </main>

    <!-- 页脚 -->
    <footer class="bg-gray-900 text-gray-300 py-12">
        <div class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-6 md:mb-0">
                    <h3 class="text-xl font-bold text-white mb-2">
                        <i class="fas fa-code mr-2"></i>技术小馆
                    </h3>
                    <p class="text-gray-400">探索技术的无限可能</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-gray-300 hover:text-white transition-colors">
                        <i class="fas fa-globe mr-2"></i>http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-8 pt-8 text-center text-gray-500 text-sm">
                © 2023 技术小馆. 保留所有权利。
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```